from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.database.models.base import TimedBaseModel


class Category(TimedBaseModel):
    __tablename__ = "category"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), nullable=False)
    price: Mapped[float]
    products = relationship("Product", back_populates="category")
    country_id: Mapped[int] = mapped_column(ForeignKey("country.id"))
    country = relationship("Country", back_populates="categories")

    def __repr__(self):
        return f"<Категория {self.name}>"

    def __str__(self):
        return self.__repr__()
